cmake_minimum_required(VERSION 3.25)

# 语言版本
set(CMAKE_C_STANDARD 17)

# 如果指定的语言版本不受支持, 则构建过程终止
set(CMAKE_C_STANDARD_REQUIRED True)

# 只弃用 ISO C++ 标准的编译器标志, 而不使用特定编译器的扩展
set(CMAKE_C_EXTENSIONS ON)

# 将 install_rpath 的设置应用在 build_rpath 上
# 在开发期间避免出现动态库找不到的问题
set(CMAKE_BUILD_WITH_INSTALL_RPATH True)

# 项目配置 ##############################################################################################################
project(c-hello_test C)

# 编译相关配置 ###########################################################################################################

# 生成 compile_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if(ENABLE_COVERAGE)
    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
    SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
endif()

include_directories(${CMAKE_SOURCE_DIR}/test)
include_directories(${CMAKE_SOURCE_DIR}/include)

# 项目生成配置 ###########################################################################################################
aux_source_directory(. test_srcs)
add_executable(${PROJECT_NAME} ${test_srcs})

target_link_libraries(${PROJECT_NAME} PRIVATE cunit zlog ${lib_configuration_name})
set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${dist_dir}/test)
set_target_properties(${PROJECT_NAME} PROPERTIES INSTALL_RPATH "\${ORIGIN}/../lib")

configure_file(${CMAKE_SOURCE_DIR}/test/zlog.conf ${dist_dir}/test/zlog.conf COPYONLY)

# 测试相关配置 ###########################################################################################################
# 执行所有测试
# ctest --test-dir build
add_test(NAME test_all COMMAND ${PROJECT_NAME})
set_tests_properties(test_all PROPERTIES WORKING_DIRECTORY ${dist_dir}/test)
